﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.transitions.easing.Regular;
import mx.transitions.Tween;
import mx.utils.Delegate;

class MiradorServiciosEventos
extends MiradorSiteSection {
	public static var EVENTOS:String = "eventos_eventos";
	public static var SERVICIOS:String = "eventos_servicios";
	public static var POR_QUE:String = "eventos_porQue";
	public static var CLIENTES:String = "eventos_clientes";
	
	private var nFrameSection:Number;
	private var mcContent:MovieClip;
	private var mcGaleria:MiradorServicioEventoGaleria;
	private var mcNavBar:MiradorEventosNavBar;
	
	
	function MiradorServiciosEventos() {
		super( MiradorSite.getApp() );
		sName = MiradorSite.EVENTOS;
		sectionChanged();
	}
			
	public function childLoaded( evnt ):Void {
		switch( evnt.target ) {
						
			case mcGaleria:
			var oData:Object = new Object();
			var oRooms:Object = MiradorSite.getApp().getRooms();
			oData.danbro = oRooms.danbro.eventos.photo;
			oData.mirador = oRooms.mirador.eventos.photo;
			oData.altos = oRooms.altos.eventos.photo;
			mcGaleria.setData(oData);
			break;
			
			case mcNavBar:
			mcNavBar.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, navbar_changed));
			break;
			
		}
	}
	
	private function navbar_changed( evnt ):Void {
		switch( evnt.data ) {
			case EVENTOS:
			nFrameSection = 2;
			break;
			
			case SERVICIOS:
			nFrameSection = 3;
			break;
			
			case POR_QUE:
			nFrameSection = 4;
			break;
			
			case CLIENTES:
			nFrameSection = 5;
			break;
			
		}
		registerTween("contentFade", new Tween( mcContent, "_alpha", Regular.easeOut, mcContent._alpha, 0, 0.5, true), false, true );
		registerTween("navBarFade", new Tween( mcNavBar, "_alpha", Regular.easeOut, mcNavBar._alpha, 0, 0.5, true), false, true );
	}
		
	private function tweenFinished(key:String, tween:Tween):Void {
		switch( key ) {
			case "contentFade":
			this.gotoAndStop( nFrameSection );
			registerTween("contentFade", new Tween(mcContent, "_alpha", Regular.easeOut, mcContent._alpha, 100, 0.7, true));
			break;
			
			case "navBarFade":
			var nX:Number = mcContent._x + mcContent.mcShadow._x + (mcContent.mcShadow._width - mcNavBar._width) /2 ;
			var nY:Number = mcContent._y + mcContent.mcShadow._y +  mcContent.mcShadow._height - 20;
			mcNavBar._x = nX;
			mcNavBar._y = nY;
			registerTween("navBarFade", new Tween( mcNavBar, "_alpha", Regular.easeOut, mcNavBar._alpha, 100, 0.5, true));
			break;
						
			default:
			super.tweenFinished(key, tween);
			break;
		}
		
	}
	
}